import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/title_view.dart';
import 'package:flutter_eve_plugin/constants/constant.dart';
import 'package:flutter_eve_plugin/model/health/sys_health_property.dart';
import 'package:flutter_eve_plugin/plugin/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/health/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class HealthAdviceWidget extends StatelessWidget {
  final PropertyHealthDataInfo info;

  const HealthAdviceWidget({Key key, this.info}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(
          state: store.state,
          healthStateViewModel: HealthStateViewModel(pushMallPage: () {
            final param = {"sub_type": this.info.healthSystem};
            PluginEve.sendMessage(PluginConstant.httpAllGoodsType,
                param: param, httpType: HttpType.POST);
          }));
    }, builder: (context, vm) {
      return Container(
        decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage(
                  imageUtilHuPo('health/icon_dotted_border@2x')),
              fit: BoxFit.fill),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: buildChildren(vm),
        ),
        width: setRatio(345),
      );
    });
  }

  List<Widget> buildChildren(AppStateViewModel vm) {
    List<Widget> list = [
      SizedBox(
        height: setRatio(25),
      ),
      HealthTitleViewWidget(
        title: '健康建议',
      ),
    ];
    switch (info.healthGrade) {
      case 0:
        list.add(
          Container(
              padding: EdgeInsets.only(
                  left: setRatio(20), right: setRatio(20), top: setRatio(25)),
              child: Text(
                info.propose,
                softWrap: true,
                textScaleFactor: 1.2,
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: setTextSp(14),
                ),
              )),
        );
        list.add(
          SizedBox(
            height: setRatio(24),
          ),
        );
        return list;
      case 1:
        list.add(
          Container(
              padding: EdgeInsets.only(
                  left: setRatio(20), right: setRatio(20), top: setRatio(25)),
              child: Text(
                info.propose,
                softWrap: true,
                textScaleFactor: 1.2,
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: setTextSp(14),
                ),
              )),
        );
        list.add(
          SizedBox(
            height: setRatio(13),
          ),
        );
        list.add(
          Row(
            children: <Widget>[
              Expanded(
                child: Container(),
              ),
              SizedBox(
                width: setRatio(98),
                height: setRatio(26),
                child: RaisedButton(
                  onPressed: vm.healthStateViewModel.pushMallPage,
                  shape: StadiumBorder(),
                  color: Color(0xff8159f5),
                  child: Text(
                    '前往商城',
                    style:
                        TextStyle(color: Colors.white, fontSize: setTextSp(14)),
                  ),
                ),
              ),
              SizedBox(
                width: setRatio(14),
              ),
            ],
          ),
        );
        list.add(
          SizedBox(
            height: setRatio(13),
          ),
        );
        return list;
      case 2:
      case 3:
        list.add(
          Container(
              padding: EdgeInsets.only(
                  left: setRatio(20), right: setRatio(20), top: setRatio(25)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    '狗医生建议：',
                    style: TextStyle(
                        color: Color(0xFF999999), fontSize: setTextSp(14)),
                  ),
                  SizedBox(
                    height: setRatio(15),
                  ),
                  Text(
                    info.propose,
                    style: TextStyle(
                        color: Color(0xFF333333), fontSize: setTextSp(14)),
                  ),
                  SizedBox(
                    height: setRatio(24),
                  ),
                ],
              )),
        );
        return list;
    }
    return [Container()];
  }
}
